{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# Further Hypothesis Testing\n",
    "\n",
    "## Assignment: ice cream\n",
    "\n",
    "This assignment contains exercises to test your understanding of various hypothesis tests from the course. It is a good idea to revise the course material thoroughly before starting.\n",
    "\n",
    "Use whatever computational resources you like to answer the questions (e.g. python, R, any other programming language, a spreadsheet, a calculator, ...)."
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### The data\n",
    "\n",
    "The file `Ice_cream.csv` contains data collected on 165 high school students. These are:\n",
    "\n",
    "* Subject ID\n",
    "* Wears glasses (0=No, 1=Yes)\n",
    "* Favourite ice cream flavour (1=Vanilla, 2=Chocolate, 3=Strawberry)\n",
    "* Score on a video game\n",
    "* Score on a puzzle\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {},
   "outputs": [],
   "source": [
    "# Library imports:\n",
    "\n",
    "import numpy as np\n",
    "import pandas as pd\n",
    "from scipy import stats\n",
    "import matplotlib.pyplot as plt\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>id</th>\n",
       "      <th>glasses</th>\n",
       "      <th>ice_cream</th>\n",
       "      <th>video</th>\n",
       "      <th>puzzle</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>70</td>\n",
       "      <td>1</td>\n",
       "      <td>2</td>\n",
       "      <td>47</td>\n",
       "      <td>57</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>86</td>\n",
       "      <td>1</td>\n",
       "      <td>3</td>\n",
       "      <td>58</td>\n",
       "      <td>31</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>141</td>\n",
       "      <td>1</td>\n",
       "      <td>3</td>\n",
       "      <td>53</td>\n",
       "      <td>56</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>172</td>\n",
       "      <td>1</td>\n",
       "      <td>1</td>\n",
       "      <td>53</td>\n",
       "      <td>61</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>113</td>\n",
       "      <td>1</td>\n",
       "      <td>1</td>\n",
       "      <td>63</td>\n",
       "      <td>61</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>...</th>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>160</th>\n",
       "      <td>31</td>\n",
       "      <td>0</td>\n",
       "      <td>1</td>\n",
       "      <td>42</td>\n",
       "      <td>56</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>161</th>\n",
       "      <td>145</td>\n",
       "      <td>0</td>\n",
       "      <td>1</td>\n",
       "      <td>36</td>\n",
       "      <td>46</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>162</th>\n",
       "      <td>187</td>\n",
       "      <td>0</td>\n",
       "      <td>1</td>\n",
       "      <td>55</td>\n",
       "      <td>52</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>163</th>\n",
       "      <td>118</td>\n",
       "      <td>0</td>\n",
       "      <td>1</td>\n",
       "      <td>58</td>\n",
       "      <td>61</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>164</th>\n",
       "      <td>137</td>\n",
       "      <td>0</td>\n",
       "      <td>3</td>\n",
       "      <td>53</td>\n",
       "      <td>61</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "<p>165 rows × 5 columns</p>\n",
       "</div>"
      ],
      "text/plain": [
       "      id  glasses  ice_cream  video  puzzle\n",
       "0     70        1          2     47      57\n",
       "1     86        1          3     58      31\n",
       "2    141        1          3     53      56\n",
       "3    172        1          1     53      61\n",
       "4    113        1          1     63      61\n",
       "..   ...      ...        ...    ...     ...\n",
       "160   31        0          1     42      56\n",
       "161  145        0          1     36      46\n",
       "162  187        0          1     55      52\n",
       "163  118        0          1     58      61\n",
       "164  137        0          3     53      61\n",
       "\n",
       "[165 rows x 5 columns]"
      ]
     },
     "execution_count": 2,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# Loading the data:\n",
    "\n",
    "data = pd.read_csv('Ice_cream.csv')\n",
    "data\n"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### The tasks"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "metadata": {},
   "outputs": [],
   "source": [
    "# We will use a significance level alpha=0.05 throughout.\n"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Answer the following questions:"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "1. Are the video game and puzzle scores normally distributed?"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "metadata": {},
   "outputs": [],
   "source": [
    "# We can use a Shapiro-Wilk test on each set of scores:\n",
    "\n",
    "# H0: The scores are normally distributed.\n",
    "# H1: The scores are not normally distributed."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "0.07658827304840088"
      ]
     },
     "execution_count": 5,
     "metadata": {},
     "output_type": "execute_result"
    },
    {
     "data": {
      "image/png": "iVBORw0KGgoAAAANSUhEUgAAAXAAAAD4CAYAAAD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N90bEa+suqCa7gVcB/5CZrwSe5Cw/XLKZ6v2ftwBfrLuW1aY+wM/IzNPAXcAVwJ6IOPMhp2n4ioArgbdExKN0v1XyIN1X5NPWBzLzseryJN1jnQeAJyJiL0B1ebK+CidmBVjJzG9Xy7fSDfRp7AV0/6Dfm5lPVMs7og9THeARcWFE7KmuPw94Pd03alrAO6rNDgO311PhZGTmX2TmbGbO0f3fxG9m5u8yZX2IiPMi4gVnrtM95nmc7ldEHK42O+v7AJCZ/wn8KCIuqaZeB3yXKexF5Rp+efgEdkgfpvqTmBHxW8ARul8FcA5wS2b+dUS8jO4r0fOB+4Dfy8yn6qt0ciLiKuBPMvPN09aH6vneVi3uBj6XmR+JiBcBtwC/DvwQeGdm/rSmMicmIvYBnwaeAzwC/D7VvxOmqBcR8XzgR8DLMvO/q7kdsU9MdYBLUsmm+hCKJJXMAJekQhngklQoA1ySCmWAS1KhDHBJKpQBLkmF+j8A+/VPAH7TPgAAAABJRU5ErkJggg==\n",
      "text/plain": [
       "<Figure size 432x288 with 1 Axes>"
      ]
     },
     "metadata": {
      "needs_background": "light"
     },
     "output_type": "display_data"
    }
   ],
   "source": [
    "# For the video game:\n",
    "\n",
    "data.video.hist(color='red')\n",
    "p_value = stats.shapiro(data.video)[1]\n",
    "p_value"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "0.000320218998240307"
      ]
     },
     "execution_count": 6,
     "metadata": {},
     "output_type": "execute_result"
    },
    {
     "data": {
      "image/png": "iVBORw0KGgoAAAANSUhEUgAAAXAAAAD4CAYAAAD1jb0+AAAABHNCSVQICAgIfAhkiAAAAAlwSFlzAAALEgAACxIB0t1+/AAAADh0RVh0U29mdHdhcmUAbWF0cGxvdGxpYiB2ZXJzaW9uMy4xLjMsIGh0dHA6Ly9tYXRwbG90bGliLm9yZy+AADFEAAAPX0lEQVR4nO3dX4xc5XnH8e+DDUripTLEZOWytAsKokFWcTKWQ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WI/IuKK6jVxcrwaEX8w6F6MfIADbwDXZuZVwHZgd0RcDXwVuCszLweOA7cMscZBuxU4vGB5lHsBMJWZ2xdc33s7sL/qx/5qeVT8FfDDzPwN4Cpar5OR60dmPlO9JrYDNeB/gQcZdC8y01EN4F3AE8AHaX2aamM1/yHgR8Oub0A9mKheeNcCj9D6wNZI9qL69x4BtiyZewbYWt3fCjwz7DoH1ItfAX5GdfHDqPdjwb//Y8A/DaMXHoHzy1MGB4BjwD7gP4ATmflmtck8cPGw6huwvwT+GHi7Wn43o9sLaH26+B8iolF9LQTAeGa+BFDdvmdo1Q3WZcB/A39bnWL7ZkRsYnT7cdJngfuq+wPthQEOZOZb2fqv0AStL+l630qbDbaqwYuITwDHMrOxcHqFTc/6XixwTWZ+gNa3bn4hIj487IKGaCPwAeCvM/P9wOuMwOmSM6l+H/RJ4O+G8fwG+AKZeQJ4FLga2BwRJz/oNCpfE3AN8MmIOELr2yWvpXVEPoq9ACAzX6xuj9E6x7kTOBoRWwGq22PDq3Cg5oH5zHy8Wn6AVqCPaj+g9YP9icw8Wi0PtBcjH+ARcVFEbK7uvxP4CK1fzNSBG6vN9gAPDafCwcnMP8nMicycpPXfwn/MzN9hBHsBEBGbIuL8k/dpnes8SOsrI/ZUm41MPzLzv4CfR8QV1dR1wE8Z0X5UbuLU6RMYcC9G/pOYEfGbwF5aXwdwDnB/Zv5ZRFxG6yj0QuBJ4Hcz843hVTpYEbEL+KPM/MSo9qL6dz9YLW4EvpOZd0bEu4H7gV8DXgA+k5mvDKnMgYqI7cA3gfOA54Hfo3rfMGL9iIh3AT8HLsvM/6nmBvraGPkAl6RSjfwpFEkqlQEuSYUywCWpUAa4JBXKAJekQhngklQoA1ySCvX/+pwPMYyGOPgAAAAASUVORK5CYII=\n",
      "text/plain": [
       "<Figure size 432x288 with 1 Axes>"
      ]
     },
     "metadata": {
      "needs_background": "light"
     },
     "output_type": "display_data"
    }
   ],
   "source": [
    "# For the puzzle:\n",
    "\n",
    "data.puzzle.hist(color='blue', bins=10)\n",
    "p_value = stats.shapiro(data.puzzle)[1]\n",
    "p_value"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "metadata": {},
   "outputs": [],
   "source": [
    "# The video game scores are not significantly divergent from normal (p > alpha),\n",
    "# but the puzzle scores are (p < alpha).\n",
    "\n",
    "# (A Bonferroni correction for multiple testing does not change these conclusions.)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "2. Is the video game as hard as the puzzle?"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 8,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "0.20001110509253145"
      ]
     },
     "execution_count": 8,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# Because the same students generate both scores, the samples are not independent.\n",
    "\n",
    "# Although the puzzle scores are not normally distributed, we *do* have a big \n",
    "# enough sample size (n > 75) to use a paired sample t-test to investigate the \n",
    "# mean of the score differences (puzzle - video).\n",
    "\n",
    "# We will consider this to be two-tailed test:\n",
    "\n",
    "# H0: mean(puzzle - video) = 0\n",
    "# H1: mean(puzzle - video) != 0\n",
    "\n",
    "p_2tailed = stats.ttest_rel(data.puzzle, data.video).pvalue\n",
    "p_2tailed\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 9,
   "metadata": {},
   "outputs": [],
   "source": [
    "# Here, p > alpha so we accept the null hypothesis that the video game is \n",
    "# of the same difficulty as the puzzle."
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "3. Is wearing glasses associated with a lower score on the puzzle game?"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 10,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "image/png": "iVBORw0KGgoAAAANSUhEUgAAAYgAAAEGCAYAAAB/+QKOAAAABHNCSVQICAgIfAhkiAAAAAlwSFlzAAALEgAACxIB0t1+/AAAADh0RVh0U29mdHdhcmUAbWF0cGxvdGxpYiB2ZXJzaW9uMy4xLjMsI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555Jj/+8Y956aWX6NOnDz/84Q8/te9FF13ERRddxIsvvsg+++yTPP6ee+7J9OnTmT17Nvfffz/f+ta3ALj33ns59thjmTNnDnPnzqWyspI5c+bwxhtvMH/+fObNm8fZZ58NQHV1NTfeeCOzZs3iuuuu44ILLgBg/PjxPPHEE8ydO5eHH364GMNjZq1UMZ9iEnAbsDAiftpg08NA/VNJo4HfJHZ/Ahgmabfs5vSwrG2b1LNnTyorKwEYMGAAS5cuZe3ataxZs4Yvf/nLAIwePZqZM2d+at/nn3+e0047DYCvf/3ryeN/+OGHjB07lj59+nDaaafx8ssvAzBw4EBuv/12fvCDHzBv3jw6d+7MAQccwKuvvso3v/lNHn/8cXbZZRfq6up47rnnOO2006isrOTcc89lxYoVAAwePJizzjqLn//852zcuLHFx8bMWq9inkEMBs4AviJpTvY6HrgGOEbSYuCYbB1JVZJuBchuTl8FvJi9xtffsN4W7bDDDh8tt2vXjg0bNrTo8SdMmMBee+3F3Llzqamp4YMPPgBgyJAhzJw5k3333ZczzjiDO++8k9122425c+dy1FFHcfPNN3POOeewadMmunTpwpw5cz56LVy4EICJEydy9dVXs2zZMiorK1m9enWL1m5mrVfRAiIino0IRUTfiKjMXo9FxOqIODoiDsx+vp31r4mIcxrsPzki/jl73V6sOvOy6667sttuu/HMM88AcNddd310NtHQoEGDProkdd999yWPtXbtWvbee2+222477rrrro/+0n/ttdfYc889GTt2LGPGjGH27Nm89dZbbNq0iVNOOYWrrrqK2bNns8suu9CzZ0+mTp0KFD4lPXfuXKBwb+Lwww9n/PjxdO3alWXLliVrMLO2p81PtdFYa3ry4Y477uC8885j3bp1HHDAAdx++6dz8Gc/+xmnn346119/PSeccAK77rrrp/pccMEFnHLKKUydOpWhQ4ey8847A/D0009z7bXX0qFDBzp16sSdd97JG2+8wdlnn82mTZsA+NGPfgTAPffcw/nnn8/VV1/Nhx9+yMiRI+nXrx+XXHIJixcvJiI4+uij6devXxFHxMxaE0UkHw7aJlVVVUXjLwxauHAhhxxySE4VfX7r1q1jxx13RBL33XcfU6ZM4Te/Sd22yce2Pr7N4cdcW6fW9MfetkzSrIioSm0ruzOIbc2sWbO48MILiQi6dOnC5MmT8y7JzMqEA6KVO/LIIz+6H2BmVkptfjZXMzPbOg4IMzNLckCYmVmSA8LMzJLK7yb1jB+17PGGXr5Vu5111lmMGDGCU089tWXrMTNrIT6DMDOzJAdECVx11VV84Qtf4JhjjmHUqFFcd911n9g+fvx4Bg4cSO/evamurqb+w4s33HADvXr1om/fvowcORKAP/zhD1RWVlJZWcmhhx7Ke++9B8C1117LwIED6du3L1deeSUAf//73znhhBPo168fvXv35v777y/hb21m27ryu8RUYjU1NTz44IP8+c9/ZsOGDfTv358BAwZ8os+FF17IFVdcAcAZZ5zBI488woknnsg111zD3/72N3bYYQfWrFkDwHXXXcfNN9/M4MGDqauro2PHjkybNo3FixfzwgsvEBGcdNJJzJw5k1WrVrHPPvvw6KOPAoU5m8zMmstnEEX27LPPcvLJJ7PjjjvSuXNnTjzxxE/1mTFjBocffjh9+vThqaeeYsGCBQD07duXb3zjG9x99920b1/I8sGDB/Od73yHG264gTVr1tC+fXumTZvGtGnTOPTQQ+nfvz+LFi1i8eLF9OnTh9///vdceumlPPPMM8l5nMzMmuKAKLItzXW1fv16LrjgAh544AHmzZvH2LFjWb9+PQCPPvoo48aNY9asWQwYMIANGzZw2WWXceutt/L+++8zaNAgFi1aRERw+eWXfzRV95IlSxgzZgwHHXQQs2bNok+fPlx++eWMHz++FL+ymbURDogi+9KXvsRvf/tb1q9fT11d3UeXe+rVh0HXrl2pq6vjgQceAGDTpk0sW7aMoUOH8pOf/IQ1a9ZQV1fHK6+8Qp8+fbj00kupqqpi0aJFHHvssUyePJm6ujoA3njjDVauXMny5cvZaaedOP300/ne977H7NmzS/vLm9k2rfzuQWzlY6lba+DAgZx00kn069eP/fffn6qqqk9c6unSpctH3wbXo0cPBg4cCMDGjRs5/fTTWbt2LRHBxRdfTJcuXfj+97/PjBkzaNeuHb169eK4445jhx12YOH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},
     "output_type": "display_data"
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "no glasses: n = 108 , mean(puzzle) = 52.842592592592595\n",
      "glasses: n = 57 , mean(puzzle) = 52.56140350877193\n"
     ]
    }
   ],
   "source": [
    "# Let's plot the scores for the two groups:\n",
    "\n",
    "puzzle_glasses = data.puzzle[data.glasses==1]\n",
    "puzzle_no_glasses = data.puzzle[data.glasses==0]\n",
    "\n",
    "xlab = 'puzzle'\n",
    "ylab = 'freq'\n",
    "\n",
    "bins = np.linspace(data.puzzle.min(), data.puzzle.max()+1, 10)\n",
    "ax = plt.axes()\n",
    "ax.set_xlabel(xlab)\n",
    "ax.set_ylabel(ylab)\n",
    "\n",
    "#plt.hist(data.puzzle, bins, alpha=0.5)\n",
    "plt.hist(puzzle_no_glasses, bins, alpha=0.5, label='no glasses', color='C0' )\n",
    "plt.hist(puzzle_glasses, bins, alpha=0.5, label='glasses', color='C1' )\n",
    "\n",
    "ax.legend(loc='upper left')\n",
    "plt.show()\n",
    "\n",
    "print('no glasses: n =', len(puzzle_no_glasses), \n",
    "      ', mean(puzzle) =', puzzle_no_glasses.mean())\n",
    "print('glasses: n =', len(puzzle_glasses),\n",
    "     ', mean(puzzle) =', puzzle_glasses.mean())"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 11,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "0.4409296300462722"
      ]
     },
     "execution_count": 11,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# The \"glasses\" group is just below the sample size that would allow a reliable\n",
    "# p-value to be obtained from a t-test using non-normal data (n>75).\n",
    "\n",
    "# Instead, we will use a non-parametric alternative. The two samples are\n",
    "# independent, so we can use a Mann-Whitney U-test to compare their distributions.\n",
    "\n",
    "# Note that the question as posed is a one-tailed hypothesis test:\n",
    "\n",
    "# H0: a random sample from puzzle_glasses is on average the same as \n",
    "#     a random sample from puzzle_no_glasses.\n",
    "# H1: a random sample from puzzle_glasses is on average less than \n",
    "#     a random sample from puzzle_no_glasses\n",
    "\n",
    "p_1tailed = stats.mannwhitneyu(puzzle_glasses, \n",
    "                               puzzle_no_glasses, \n",
    "                               alternative='less').pvalue\n",
    "\n",
    "p_1tailed"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 12,
   "metadata": {},
   "outputs": [],
   "source": [
    "# The result is p > alpha, so we conclude that glasses wearers do not score\n",
    "# significantly lower on the puzzle than non-wearers."
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "4. Do glasses wearers have different ice cream preferences to non-wearers?"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 13,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th>ice_cream</th>\n",
       "      <th>1</th>\n",
       "      <th>2</th>\n",
       "      <th>3</th>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>glasses</th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>47</td>\n",
       "      <td>32</td>\n",
       "      <td>29</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>31</td>\n",
       "      <td>8</td>\n",
       "      <td>18</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "ice_cream   1   2   3\n",
       "glasses              \n",
       "0          47  32  29\n",
       "1          31   8  18"
      ]
     },
     "execution_count": 13,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# To test whether two categorical variables are independent, we use a \n",
    "# chi-squared test:\n",
    "\n",
    "# H0: glasses and ice_cream are independent.\n",
    "# H1: glasses and ice_cream are not independent.\n",
    "\n",
    "# The contingency table:\n",
    "\n",
    "obs = pd.crosstab(data.glasses, data.ice_cream)\n",
    "obs"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 14,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([[51.05454545, 26.18181818, 30.76363636],\n",
       "       [26.94545455, 13.81818182, 16.23636364]])"
      ]
     },
     "execution_count": 14,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# The expected frequencies:\n",
    "\n",
    "stats.contingency.expected_freq(obs)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 15,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "0.0834314371780616"
      ]
     },
     "execution_count": 15,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# All expected frequencies are above 5, so we are OK to proceed with the test:\n",
    "\n",
    "stats.chi2_contingency(obs)[1]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 16,
   "metadata": {},
   "outputs": [],
   "source": [
    "# p > alpha, so we accept the null hypothesis that the variables are independent."
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "5. Is the video game score independent of favourite ice cream?"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 17,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "image/png": "iVBORw0KGgoAAAANSUhEUgAAAYgAAAEGCAYAAAB/+QKOAAAABHNCSVQICAgIfAhkiAAAAAlwSFlzAAALEgAACxIB0t1+/AAAADh0RVh0U29mdHdhcmUAbWF0cGxvdGxpYiB2ZXJzaW9uMy4xLjMsIGh0dHA6Ly9tYXRwbG90bGliLm9yZy+AADFEAAAgAElEQVR4nO3de3QV5b3/8feXi0Quyi1QKmLwH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pIEREJFSd+x4ERZVPlPeNZVT+qOw9e/aQnZ3Nl19+yd69exk+fDi33HJLpduUlJQwZswYNm7cSGlpKRkZGSxatIiioiJeeeUVRo4cmcg9AKBp06bs3Lkz4eOKSM2lM4iINWrUiCVLlrBq1SoKCwt59tlnee211yrd5uabb6Z///6sWrWKt99+m9tvvx2ITfY3e/bs0G327t2b8NqrquJ7p7IWEUmcyM4gzGw6MAjY4u6nBm2PA52CLs2Bz909M2TbImAHsA/YG+9LHDWBmdG0aVMgNidTaWnpIedG2rx5MwMGDChb7ty5MwA33HADa9euJTMzk7y8PFq0aMHf/vY39uzZw65du1i4cCFDhgzhs88+o7S0lNtuu40hQ4Zwxx13kJaWxtVXX80111zDqlWrWLJkCc8//zwzZszgkUceAeDaa69l6dKltGjRgjlz5pCens6GDRsYP348W7dupXHjxjzwwAOcdNJJjB49mpYtW/LGG2/QrVs3mjVrxqZNmygqKqJ169Zs3LiR++67r+zb47169eL+++8v2xcRqf6iPIOYCeSUb3D3C909MwiFJ4GnKtm+b9C3xobDAfv27SMzM5M2bdrQv3//sum+b775ZhYuXHhQ//HjxzNmzBj69u3LpEmT2LRpEwC33347vXv3prCwkGuuuQaIzco6a9YslixZQlpaGvPnz2flypUsXbqUa6+9FncnOzubl156CYD8/Hx27txJaWkpy5Yto3fv3gDs2rWLbt26sXLlSs4+++yyy2Djxo3jvvvuo6CggDvvvJMrr7yyrM53332X5557jrvuuguAgoICnn76aWbPns3YsWOZOXNmWb8vv/xS4SBSw0QWEO7+IhD6HGmL/RP6AuCxqN6/Oqlfvz6FhYUUFxezYsUK1qxZA8Ctt97K4MGDD+p/7rnn8v7773PZZZexbt06unbtytatW0PH7t+/f9kU3u7OjTfeSOfOnfnBD37ARx99RElJCd27d6egoIAdO3bQqFEjzjzzTPLz83nppZfKAqJevXpceOGFAPz0pz9l2bJlX5vKOzMzk8svv5zNmzeXvff5559P/fr1y5YHDx7MkUceWbbumWeeobS0lOnTpzN69OhvfyBFJKlSdZO6N1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3836DcrGEMkpXQPQuTwzCN2z+E7xM4oKgqbw8aAxe6e+7XG2FxFItWOziBEDs8cYjPUDuerp+Md8CJwEYCZnQp0DtpfA3qZ2X8H6xqb2YnAOiDjQDtwMfCvaMsXOTQFhMhhcPe3gGbARweeClbO/UBTM1tN7Gl6K4JttgKjgceCda8BJ7n7HmIznM41szeJPX1valJ2RKQSms1VRERC6QxCRERCKSBERCSUAkJEREIpIEREJJQCQkREQikgREQklAJCRERC/X9OEpyIWljVMAAAAABJRU5ErkJggg==\n",
      "text/plain": [
       "<Figure size 432x288 with 1 Axes>"
      ]
     },
     "metadata": {
      "needs_background": "light"
     },
     "output_type": "display_data"
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "1: Vanilla: n = 78 , mean(video) = 51.794871794871796\n",
      "2: Chocolate: n = 40 , mean(video) = 46.65\n",
      "3: Strawberry: n = 47 , mean(video) = 55.851063829787236\n"
     ]
    }
   ],
   "source": [
    "# Again, let's plot the scores for the relevant groups:\n",
    "\n",
    "video_1 = data.video[data.ice_cream==1]\n",
    "video_2 = data.video[data.ice_cream==2]\n",
    "video_3 = data.video[data.ice_cream==3]\n",
    "\n",
    "xlab = 'video'\n",
    "ylab = 'freq'\n",
    "\n",
    "bins = np.linspace(data.video.min(), data.video.max()+1, 15)\n",
    "ax = plt.axes()\n",
    "ax.set_xlabel(xlab)\n",
    "ax.set_ylabel(ylab)\n",
    "\n",
    "plt.hist(video_1, bins, alpha=0.5, label='1: Vanilla', color='yellow' )\n",
    "plt.hist(video_2, bins, alpha=0.5, label='2: Chocolate', color='brown' )\n",
    "plt.hist(video_3, bins, alpha=0.5, label='3: Strawberry', color='pink' )\n",
    "\n",
    "ax.legend(loc='upper left')\n",
    "plt.show()\n",
    "\n",
    "print('1: Vanilla: n =', len(video_1), \n",
    "      ', mean(video) =', video_1.mean())\n",
    "print('2: Chocolate: n =', len(video_2), \n",
    "      ', mean(video) =', video_2.mean())\n",
    "print('3: Strawberry: n =', len(video_3), \n",
    "      ', mean(video) =', video_3.mean())\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 18,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "2.9627727657836244e-05"
      ]
     },
     "execution_count": 18,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# This question asks us to test whether the mean video game scores for the three\n",
    "# ice cream groups are the same. This requires a one-way ANOVA test:\n",
    "\n",
    "# H0: The means of the three groups are the same.\n",
    "# H1: The means of the three groups are not the same.\n",
    "\n",
    "p_value = stats.f_oneway(video_1, video_2, video_3).pvalue\n",
    "p_value"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 19,
   "metadata": {},
   "outputs": [],
   "source": [
    "# The result is p < alpha, so we reject the null hypothesis and conclude\n",
    "# that there is a significant association between favourite ice cream and \n",
    "# video game score."
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "---"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.7.6"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 4
}
